package edu.ccut.saturn.studio.util;

import java.util.HashMap;
import java.util.Map;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.core.util.xml.SaturnW3CUtil;
//import edu.ccut.saturn.studio.logic.model.xml.ModelXmlUtils;

public class ValidateByName{
	private static Map<String,Document> map;
	private static Map<String,String> validateNames;
	
	//把得到的Map（帮都：：剋，到Q们他）传进来，得到Map<名称，剋>
	public static Map<String,String> getValidateNames(Map<String,Document> map1){
		map = map1;
		validateNames = new HashMap<String,String>();
		String [] keys = map.keySet().toArray(new String[]{});
		for(String key : keys){
			Document doc = map.get(key);
			NodeList nodeList = doc.getElementsByTagName("validate");
			for(int i = 0;i<nodeList.getLength();i++){
				Node node = nodeList.item(i);
				String name = SaturnW3CUtil.getNodeAttributeValue(node, "name");
				//String name = ModelXmlUtils.getNodeElementValue(node, "name");
				validateNames.put(name, key);//<名称，剋>
			}
		}
		return validateNames;
	}
	
	public static Document getValidateDocument(String name){
		return map.get(validateNames.get(name));
	}
}
